<template>
  <div>
    <div class="header">
      <div class="left">
        <el-row>
          <el-button type="success" class="el-icon-circle-close"
            @click="Myexport">导出</el-button
          >
        </el-row>
      </div>
      <div class="right">
        <el-input v-model="input" placeholder="查找" class="myinput"></el-input>
        <el-button class="el-icon-search sou" @click="select"></el-button>
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="type" label="类型"   width="80"> 
         <template slot-scope="scope"
          ><el-tag v-if="scope.row.type == '1'" type="success"
            >入库</el-tag
          >
          <el-tag type="info" v-else-if="scope.row.type == '0'"
            >出库</el-tag
          ></template
        >
      </el-table-column>
      <el-table-column prop="drug_name" label="药品名称" >
      </el-table-column>
      <el-table-column prop="serial_number" label="药品编号"> </el-table-column>
      <el-table-column prop="model" label="型号"> </el-table-column>
      <el-table-column prop="do_number" label="数量"> </el-table-column>
      <el-table-column prop="note" label="备注" width="350"> </el-table-column>
      <el-table-column prop="employee_real_name" label="负责人"> </el-table-column>
      <el-table-column prop="create_time" label="创建时间" > </el-table-column>
      <el-table-column prop="status" label="状态" width="80">
      <template slot-scope="scope"
          ><el-tag v-if="scope.row.status == '有效'" type="success"
            >有效</el-tag
          >
          <el-tag type="info" v-else-if="scope.row.status == '无效'"
            >无效</el-tag
          ></template
        ></el-table-column
      >
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
        <el-button
          type="primary"
          class="el-icon-edit "
           @click="mod(scope.row)"
          >修改</el-button
        ></template>
        </el-table-column
      >
    </el-table>
   
    <!-- 修改弹窗 -->
    <el-dialog  :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
          v-model="textarea"
        >
        </el-input>
        <el-button
          type="primary"
          class="el-icon-edit modbt"
          @click="setRow">保存</el-button
        ></el-table-column
      >
      </el-form>
    </el-dialog>
    <page :countNum="countNum"></page>
  </div>
</template>
<script>
import page from "../../components/report_ssh/pageFtoor.vue";
import { home, Myexport, mod } from "../../utils/api/Drug_inventory";
export default {
  name: "",
  created() {
    this.home();
  },
  components: { page },
  methods: {
    mod(row) {
      this.dialogFormVisible = true;
      this.culumnRow = row;
      this.textarea = row.note;
      // console.log(obj);
    },
    setRow() {
      let obj = {};
      obj.note = this.textarea;
      obj.id = this.culumnRow.id;
      mod(obj).then((data) => {
        console.log(data);
        this.home();
      });
      setTimeout(() => {
        this.dialogFormVisible = false;
      }, 500);
    },
    Myexport() {
      Myexport().then((data) => {
        this.download(data.data);
        // console.log(data);
      });
    },
    // 将后台返回的乱码解析成文件下载
    download(data) {
      if (!data) {
        return;
      }
      let url = window.URL.createObjectURL(new Blob([data]));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", "药品库存报表.xlsx");

      document.body.appendChild(link);
      link.click();
    },
    select() {
      this.all.search = this.input;
      this.home();
      console.log(this.input);
    },
    changePage(page) {
      this.all.index = page;
      this.home();
    },
    home() {
      home(this.all).then((data) => {
        this.tableData = data.data.data.drugInventoryVos;
        console.log(data);
        this.countNum = data.data.data.allCount;
        // console.log(this.countNum);
      });
    },
  },
  data() {
    return {
      tableData: [],
      input: "",
      dialogFormVisible: false,
      textarea: "",
      form: {
        name: "",
        region: "",
      },
      all: {
        index: "1",
        pageSize: "20",
        search: "",
      },
      countNum: 0,
      culumnRow: null,
    };
  },
};
</script>
<style lang="less" scoped>
.header {
  button {
    line-height: 5px;
    font-weight: bold;
    margin: 10px 6px;
  }
}
.left {
  float: left;
}
.right {
  float: right;
  button {
    height: 40px;
    margin: 0;
  }
  .myinput {
    width: 200px;
    height: 30px;
  }
}
.zhaungtai {
  width: 50px;
  height: 30px;
  border-style: none;
  color: white;
  background-color: rgb(38, 214, 61);
  padding: 0 1px;
  font-size: 12px;
}
.modbt {
  margin-top: 8px;
  text-align: right;
}
</style>